package com.xquant.databasemanagement.bean.table;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import javafx.beans.property.SimpleStringProperty;
import org.apache.commons.lang.StringUtils;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class PrimaryKeyBean {

    private final SimpleStringProperty primaryKeyName = new SimpleStringProperty();
    private final SimpleStringProperty primaryKeyColumn = new SimpleStringProperty();
    private final SimpleStringProperty tablespace = new SimpleStringProperty();
    private final SimpleStringProperty keyType = new SimpleStringProperty();

    @JacksonXmlProperty(isAttribute = true)
    public String getKeyType() {
        return keyType.get();
    }

    public SimpleStringProperty keyTypeProperty() {
        return keyType;
    }

    @JacksonXmlProperty(isAttribute = true)
    public void setKeyType(String keyType) {
        this.keyType.set(keyType);
    }

    @JacksonXmlProperty(isAttribute = true)
    public String getTablespace() {
        return tablespace.get();
    }

    public SimpleStringProperty tablespaceProperty() {
        return tablespace;
    }

    @JacksonXmlProperty(isAttribute = true)
    public void setTablespace(String tablespace) {
        this.tablespace.set(tablespace);
    }

    @JacksonXmlProperty(isAttribute = true)
    public String getPrimaryKeyName() {
        return primaryKeyName.get();
    }

    public SimpleStringProperty primaryKeyNameProperty() {
        return primaryKeyName;
    }

    @JacksonXmlProperty(isAttribute = true)
    public void setPrimaryKeyName(String primaryKeyName) {
        this.primaryKeyName.set(primaryKeyName);
    }

    @JacksonXmlProperty(isAttribute = true)
    public String getPrimaryKeyColumn() {
        return primaryKeyColumn.get();
    }

    public SimpleStringProperty primaryKeyColumnProperty() {
        return primaryKeyColumn;
    }

    @JacksonXmlProperty(isAttribute = true)
    public void setPrimaryKeyColumn(String primaryKeyColumn) {
        this.primaryKeyColumn.set(primaryKeyColumn);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (obj instanceof PrimaryKeyBean){
            PrimaryKeyBean primaryKeyBean = (PrimaryKeyBean) obj;
            return StringUtils.equals(primaryKeyBean.getPrimaryKeyName(),this.getPrimaryKeyName()) &&
                    StringUtils.equals(primaryKeyBean.getPrimaryKeyColumn(),this.getPrimaryKeyColumn())&&
                    StringUtils.equals(primaryKeyBean.getTablespace(),this.getTablespace())&&
                    StringUtils.equals(primaryKeyBean.getKeyType(),this.getKeyType());
        }
        return false;
    }
}
